//
//  TSTabBarController.m
//  chart
//
//  Created by xu on 15/7/21.
//  Copyright (c) 2015年 xu. All rights reserved.
//

#import "TSTabBarController.h"
#import "TSLoginViewController.h"

@implementation TSTabBarController{
    BOOL isFirstLoad;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    isFirstLoad = YES;
    
    NSArray *tabBarTitle = @[@"接收", @"发送", @"查询", @"个人"];
    for (NSUInteger i = 0; i < self.viewControllers.count; i++) {
        UIViewController *viewController = [self.viewControllers objectAtIndex:i];
        if ([viewController isMemberOfClass:[UINavigationController class]]) {
            viewController = [[(UINavigationController *)viewController viewControllers] firstObject];
        }
        viewController.tabBarItem = [self tabBarItemWithImage:[NSString stringWithFormat:@"nav_nor_%zd", i+1] SelectedImgName:[NSString stringWithFormat:@"nav_hlr_%zd", i+1]];
        viewController.tabBarItem.tag = i;
        viewController.tabBarItem.title = tabBarTitle[i];
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    if (isFirstLoad) {
        TSLoginViewController *login_vc = [[TSLoginViewController alloc] init];
        TSBaseNavigationController *nav = [[TSBaseNavigationController alloc] initWithRootViewController:login_vc];
        [self presentViewController:nav animated:YES completion:nil];
        
        isFirstLoad = NO;
    }
}

#pragma mark-- tabBarItemImage
- (UITabBarItem *)tabBarItemWithImage:(NSString *)imageName SelectedImgName:(NSString *)selectedImgName {
    UIImage *norImage = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIImage *selImage = [[UIImage imageNamed:selectedImgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:nil image:norImage selectedImage:selImage];
    
    return item;
}

@end
